package com.ruoyi.learnSchedule.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.learnSchedule.domain.learnSchedule;
import com.ruoyi.learnSchedule.service.IlearnScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 记录学习进度 Controller
 * 
 * @author 劳雅玲
 * @date 2024-04-26
 */
@RestController
@RequestMapping("/learnSchedule/schedule")
public class learnScheduleController extends BaseController
{
    @Autowired
    private IlearnScheduleService learnScheduleService;

    /**
     * 查询记录学习进度 列表
     */
    @PreAuthorize("@ss.hasPermi('learnSchedule:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(learnSchedule learnSchedule)
    {
        startPage();
        List<learnSchedule> list = learnScheduleService.selectlearnScheduleList(learnSchedule);
        return getDataTable(list);
    }

    /**
     * 导出记录学习进度 列表
     */
    @PreAuthorize("@ss.hasPermi('learnSchedule:schedule:export')")
    @Log(title = "记录学习进度 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, learnSchedule learnSchedule)
    {
        List<learnSchedule> list = learnScheduleService.selectlearnScheduleList(learnSchedule);
        ExcelUtil<learnSchedule> util = new ExcelUtil<learnSchedule>(learnSchedule.class);
        util.exportExcel(response, list, "记录学习进度 数据");
    }

    /**
     * 获取记录学习进度 详细信息
     */
    @PreAuthorize("@ss.hasPermi('learnSchedule:schedule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(learnScheduleService.selectlearnScheduleById(id));
    }

    /**
     * 新增记录学习进度 
     */
    @PreAuthorize("@ss.hasPermi('learnSchedule:schedule:add')")
    @Log(title = "记录学习进度 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody learnSchedule learnSchedule)
    {
//        return toAjax(learnScheduleService.insertlearnSchedule(learnSchedule));
        return toAjax(learnScheduleService.insertOrUpdatelearnSchedule(learnSchedule));
    }

    /**
     * 修改记录学习进度 
     */
    @PreAuthorize("@ss.hasPermi('learnSchedule:schedule:edit')")
    @Log(title = "记录学习进度 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody learnSchedule learnSchedule)
    {
        return toAjax(learnScheduleService.updatelearnSchedule(learnSchedule));
    }

    /**
     * 删除记录学习进度 
     */
    @PreAuthorize("@ss.hasPermi('learnSchedule:schedule:remove')")
    @Log(title = "记录学习进度 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(learnScheduleService.deletelearnScheduleByIds(ids));
    }
}
